package bmptest.bmp.service.logo;

import bmptest.bmp.entity.Category;
import bmptest.bmp.entity.Logo;
import bmptest.bmp.mapper.logo.LogoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.UUID;

import java.util.List;

@Service
public class LogoService {

    @Autowired
    LogoMapper logoMapper;
    Category category;

    public Logo getLogoCategory(int i){
        return logoMapper.getLogoCategory(i);
    }

    public List<Logo> list(){
        return logoMapper.list();
    }

    public Integer addbmplogo(Logo l){
        return logoMapper.addbmplogo(l);
    }

    public Integer addcategory(Logo l){
        return logoMapper.addcategory(l);
    }

    private String getUUID() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    @Transactional
    public void addAll(Logo l){
        String logoid = this.getUUID();
        String cid =this.getUUID();
        l.setId(logoid);
        String categoryId = l.getCategory().getId();
        l.setCid(categoryId);
        this.addbmplogo(l);
/*        this.addcategory(l);*/
    }

    public void delete(String id){
        logoMapper.delete(id);
    }

    public void updateall(Logo l) {
        String cid = l.getCategory().getId();
        l.setCid(cid);
        logoMapper.update(l);
    }
}
